# coding=utf-8
from sutras import models


def get_vow_list():
    vow_objs = models.VowConfig.objects.all()
    vows = []
    for vow_obj in vow_objs:
        vows.append({
            "id": vow_obj.id,
            "name": vow_obj.name,
            "content": vow_obj.content
        })
    return vows


def delete_vow(vow_id):
    models.VowConfig.objects.filter(pk=vow_id).delete()


def get_vow(vow_id):
    vow = models.VowConfig.objects.filter(pk=vow_id).first()
    if not vow:
        return None
    return {
        "id": vow.id,
        "name": vow.name,
        "content": vow.content,
    }


def create_vow(name, content):
    models.VowConfig.objects.create(
        name=name, content=content)


def update_vow(id, name, content):
    models.VowConfig.objects.filter(pk=id).update(
        name=name, content=content)
